-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support native JSON module #135
base: main
Are you sure you want to change the base?
Conversation
34f541f
to
ce91c57
Compare
I've just run |
Elixir 1.18+ comes with the JSON module out of the box so there is no need for Jason anymore. This commit marks Jason as an optional dependency and upates the code to use JSON if available and Jason for older Elixir versions.
ce91c57
to
759d8ea
Compare
# is listed as an optional dependency). | ||
if Version.match?(System.version(), ">= 1.18.0"), | ||
do: JSON, | ||
else: Jason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
I think this may generate compile warnings. I tried compiling in v1.180 and simulating Jason is not available (changing it to something different, like Jason2
) and it generates a compile warning even not being used in runtime.
And that may happen also in the other direction (trying to find JSON
in Elixir < v1.17, but haven't tested that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. I will create two plain Phoenix projects (one with Jason and other without) and see how it behaves.
If this throws warnings we may need to ask in the forum how to handle it properly.
Since Elixir 1.18 there is a native
JSON
module, so new projects don't needJason
and many don't have it. This pull request updates the error tracker so:JSON
module for Elixir 1.18 and newer. On older versions we still default toJason
just like we did before.encode_to_iodata!
function which is the most performant and provided by both libraries.JSON
module can't pretty print likeJason
does. Instead we are now pretty printing in the client using JSON.stringify which is widely available across all browsers.There should not be any user-facing changes. Users will still see the JSON context formatted just like they did before but now the ErrorTracker works well on Elixir 1.18 and newer projects that don't include Jason. We also don't force it for such projects as a native alternative exists.
Closes #131